﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjetS5
{
    public class Effect
    {
        public Effect(DB_Effect Effect)
        {
            effect = Effect;
            durationLeft = effect.Duration;
            ticksLeft = effect.NumberOfTicks;
            valueOfAffection = new Random().Next(effect.Affect.Value[0], effect.Affect.Value[1]);
        }

        public int getThisTickValue()
        {
            int toReturn = 0;
            switch (effect.TickType.Type)
            {
                case "constant":
                    toReturn = valueOfAffection / effect.NumberOfTicks;
                    break;
                case "croissant" :
                    if (multiplier == 0)
                    {
                        float sum = 0;
                        for (int i = 0; i < ticksLeft; i++)
                        {
                            sum += (float)valueOfAffection / ((float)ticksLeft);
                        }
                        multiplier = sum / valueOfAffection;
                    }
                    toReturn = (int)((float)valueOfAffection / ((float)ticksLeft * multiplier));
                    break;
                case "décroissant" :
                    if (multiplier == 0)
                    {
                        float sum = 0;
                        for (int i = 0; i < ticksLeft; i++)
                        {
                            sum += (float)valueOfAffection / ((float)effect.NumberOfTicks - ticksLeft + 1);
                        }
                        multiplier = sum / valueOfAffection;
                    }
                    toReturn = (int)((float)valueOfAffection / ((float)(effect.NumberOfTicks - ticksLeft + 1) * multiplier));
                    break;
            }
            return toReturn;
        }

        public float HowItAffect(String statistic)
        {
            return effect.Affect.Key.Name == statistic ? (float)valueOfAffection : 0;
        }

        public DB_Effect effect;
        public TimeSpan durationLeft;
        public int ticksLeft;
        public int valueOfAffection;

        private float multiplier = 0;
    }
}
